package com.test.BlockingQueueTest;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yang on 17/3/27.
 */
public class TeaGetQuestion {

    public static String getJiaoCai(String token) throws Exception {
        String path = Basic.teaApiRoot + "/teacher/tiku-new/get-jiaocai";
        String url = path + "?token=" + token;
        String response= ConnectionTest.sendGet(url);
        List<String> jiaoCaiIds = new ArrayList();
        String jiaoCaiId = null;

        JSONObject jsonObject = new JSONObject(response);
        JSONArray data = jsonObject.optJSONArray("data");
        for (int i = 0; i < data.length(); i++) {
            JSONObject jsonOne = data.getJSONObject(i);
            JSONArray list = jsonOne.optJSONArray("list");
            for (int j = 0; j < list.length(); j++) {
                JSONObject jsonList = list.optJSONObject(j);
                jiaoCaiId = jsonList.optString("jiaoCaiId");
                jiaoCaiIds.add(jiaoCaiId);
            }
        }
        int result = (int) ((float) Math.random() * jiaoCaiIds.size());
        return jiaoCaiIds.get(result).toString();
    }

    public static void getSection(String token, String jiaocaiId) throws Exception {
        String path = Basic.teaApiRoot + "/teacher/tiku-new/get-section";
        String url = path + "?token=" + token + "&jiaoCaiId=" + jiaocaiId + "&version=" + "290";
        String response = ConnectionTest.sendGet(url);

        JSONObject jsonObject = new JSONObject(response);
        String data = jsonObject.optString("data");
        JSONObject jsonObject1 = new JSONObject(data);
        String ksList = jsonObject1.optString("ksList");
        JSONObject jcObject = new JSONObject(ksList);
//        JSONArray ksListArray = ksObject.optJSONArray("list");
//        JSONArray jcListArray = jcObject.optJSONArray("list");


        System.out.println(jcObject);

//        String ksList = jsonObject.optString("ksList");
//        String jcList = jsonObject.optString("jcList");
//        System.out.println(ksList);






    }

    public static void getHomeworkQuestion(String token){

    }

    public static void main(String[] args) throws Exception {
        String token = "W/ugdq2LhzHICQTxgZsbFN6x3U5flA1Wnd6+0nH+/wdf+gWH1erL9IypNye1q5oS";
//        System.out.println((getJiaoCai(token)));
        getSection(token, "517");
    }
}
